import requests
from config import BASE_URL


# 定义类方法
class TestLogin:
    # 前置
    def setup_method(self):
        # 获取验证码
        response = requests.get(BASE_URL + "/api/captchaImage")
        self.uuid = response.json()["uuid"]

    # case01登录成功
    def test_login_success(self):
        url = BASE_URL + "/api/login"
        data = {
            "username": "admin",
            "password": "HM_2023_test",
            "code": "2",
            "uuid": self.uuid
        }
        response = requests.post(url, json=data)
        print(response.json())
        assert response.status_code == 200
        assert "成功" in response.json()["msg"]

    #     case2:用户名为空
    def test_login_username_null(self):
        url = BASE_URL + "/api/login"
        data = {
            "username": "",
            "password": "HM_2023_test",
            "code": "2",
            "uuid": self.uuid
        }
        response = requests.post(url, json=data)
        print(response.json())
        assert response.status_code == 200
        assert response.json()["msg"] == "用户不存在/密码错误"
